/**
 * Utility functions for card unit tests
 * Team 15, 3/12/14
 *
 */

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h> 
#include <assert.h>
#include "rngs.h"
#include <math.h>

/*
 * Function to convert number to string description
 */
char* getCard(int cardNo){
    if (cardNo == curse){
        return "curse";
    }
    if (cardNo == estate){
        return "estate";
    }
    if (cardNo == duchy){
        return "duchy";
    }
    if (cardNo == province){
        return "province";
    }
    if (cardNo == copper){
        return "copper";
    }
    if (cardNo == silver){
        return "silver";
    }
    if (cardNo == gold){
        return "gold";
    }
    if (cardNo == adventurer){
        return "adventurer";
    }
    if (cardNo == council_room){
        return "council_room";
    }
    if (cardNo == feast){
        return "feast";
    }
    if (cardNo == gardens){
        return "gardens";
    }
    if (cardNo == mine){
        return "mine";
    }
    if (cardNo == remodel){
        return "remodel";
    }
    if (cardNo == smithy){
        return "smithy";
    }
    if (cardNo == village){
        return "village";
    }
    if (cardNo == baron){
        return "baron";
    }
    if (cardNo == great_hall){
        return "great_hall";
    }
    if (cardNo == minion){
        return "minion";
    }
    if (cardNo == steward){
        return "steward";
    }
    if (cardNo == tribute){
        return "tribute";
    }
    if (cardNo == ambassador){
        return "ambassador";
    }
    if (cardNo == cutpurse){
        return "cutpurse";
    }
    if (cardNo == embargo){
        return "embargo";
    }
    if (cardNo == outpost){
        return "outpost";
    }
    if (cardNo == salvager){
        return "salvager";
    }
    if (cardNo == sea_hag){
        return "sea_hag";
    }
    if (cardNo == treasure_map){
        return "treasure_map";
    }
    return "fail";
}

/**
 * helper function for detecting differences in gamestates
 *
 */

int gameStateDiff(struct gameState *state1, struct gameState *state2){
  int i, j;
  
  //check number of players
  if(state1->numPlayers != state2->numPlayers){
    printf("Mismatch Number of Players\n");
    return 0;
  }
  //check supply counts
  for(i = 0; i < treasure_map + 1; i++){
    if(state1->supplyCount[i] != state2->supplyCount[i]){
      printf("Mismatch Number of SupplyCounts at %d\n", i);
      return 0;
    }
  }
  //check embargo tokens
  for(i = 0; i < treasure_map + 1; i++){
    if(state1->embargoTokens[i] != state2->embargoTokens[i]){
      printf("Mismatch Number of embargo tokens at %d\n", i);
      return 0;
    }
  }
  //check outpost played
  if(state1->outpostPlayed != state2->outpostPlayed){
    printf("Mismatch outpost played\n");
    return 0;
  }
  //check outpost turn
  if(state1->outpostTurn != state2->outpostTurn){
    printf("Mismatch outpost turn\n");
    return 0;
  }
  //check whose turn
  if(state1->whoseTurn != state2->whoseTurn){
    printf("Mismatch whose turn. state1: %d\t state2: %d\n", state1->whoseTurn, state2->whoseTurn);
    return 0;
  }
  // check phase
  if(state1->phase != state2->phase){
    printf("Mismatch Phase\n");
    return 0;
  }
  // check number of actions
  if(state1->numActions != state2->numActions){
    printf("Mismatch Number of Actions\n");
    return 0;
  }
  // check coins
  if(state1->coins != state2->coins){
    printf("Mismatch Coins: %d vs. %d\n", state1->coins, state2->coins);
    return 0;
  }
  // check number of buys
  if(state1->numBuys != state2->numBuys){
    printf("Mismatch Number of buys\n");
    return 0;
  }
  // check hand
  for(i = 0; i < MAX_PLAYERS; i++){
    for(j = 0; j < MAX_HAND; j++){
      if(state1->hand[i][j] != state2->hand[i][j]){
    printf("Mismatch Hand at player %d, card %d\n", i, j);
    return 0;
      }
    }
  }
  //check handCount
  for(i = 0; i < MAX_PLAYERS; i++){
    if(state1->handCount[i] != state2->handCount[i]){
      printf("Mismatch hand count at player %d\n", i);
      return 0;
    }
  }
  //check deck
  for(i = 0; i < MAX_PLAYERS; i++){
    for(j = 0; j < MAX_DECK; j++){
      if(state1->deck[i][j] != state2->deck[i][j]){
    printf("Mismatch Deck at player %d, deck %d\n", i, j);
    return 0;
      }
    }
  }
  //check deckCount
  for(i = 0; i < MAX_PLAYERS; i++){
    if(state1->deckCount[i] != state2->deckCount[i]){
      printf("Mismatch deck count at player %d\n", i);
      return 0;
    }
  }
  //check discard
  for(i = 0; i < MAX_PLAYERS; i++){
    for(j = 0; j < MAX_DECK; j++){
      if(state1->discard[i][j] != state2->discard[i][j]){
    printf("Mismatch Discard at player %d, deck %d\n", i, j);
    return 0;
      }
    }
  }
  //check discardCount
  for(i = 0; i < MAX_PLAYERS; i++){
    if(state1->discardCount[i] != state2->discardCount[i]){
      printf("Mismatch discard count at player %d\n", i);
      return 0;
    }
  }
  //check playedCards
  for(i = 0; i < MAX_DECK; i++){
    if(state1->playedCards[i] != state2->playedCards[i]){
      printf("Mismatch playedCards at deck %d\n", i);
      return 0;
    }
  }
  //check played Card Count
  if(state1->playedCardCount != state2->playedCardCount){
    printf("Mismatch Number of Played Card Count\n");
    return 0;
  }

  return 0;
}

